﻿Public Class socio

    Dim CamposVacios As Boolean
    'gjfuyf
    Dim FechaValida As Boolean
    Dim NuevaBusqueda As Boolean = True
    Dim EncontroResultado As Boolean
    Dim Editando = False

    Private Sub frmClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
        Dim Respuesta As Integer = MessageBox.Show("¿Esta seguro que quiere salir?", "Confirmar", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
        If Respuesta = 1 Then
            End
        Else
            e.Cancel = True
        End If
    End Sub

    Private Sub socio_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'ACF_PAVDataSet.tipo_documento' Puede moverla o quitarla según sea necesario.
        Me.Tipo_documentoTableAdapter.Fill(Me.ACF_PAVDataSet.tipo_documento)
        HabilitadorBotones(True)
        HabilitadorLabels(False)
    End Sub

    Private Sub HabilitadorBotones(ByVal parametro As Boolean)
        Me.cmd_Alta.Enabled = parametro
        Me.cmd_guardar.Enabled = Not (parametro)
        Me.cmd_buscar.Enabled = parametro
        Me.cmd_cancelar.Enabled = Not (parametro)
        Me.cmd_salir.Enabled = parametro
    End Sub

    Private Sub HabilitadorLabels(ByVal parametro As Boolean)
        Me.txt_apellido.Enabled = parametro
        Me.txt_calle.Enabled = parametro
        Me.txt_nombre.Enabled = parametro
        Me.txt_cp.Enabled = parametro
        Me.txt_localidad.Enabled = parametro
        Me.txt_nacionalidad.Enabled = parametro
        Me.cbx_club.Enabled = parametro
        Me.cbx_puesto.Enabled = parametro
        Me.dtp_alta_padron.Enabled = parametro
        Me.dtp_fecha_nacimiento.Enabled = parametro
        Me.txt_numero.Enabled = parametro
        Me.cbx_es_jugador.Enabled = parametro
        Me.txt_nro_documento.Enabled = parametro
        Me.cbx_tipo_documento.Enabled = parametro

        Me.txt_apellido.Text = ""
        Me.txt_calle.Text = ""
        Me.txt_nombre.Text = ""
        Me.txt_cp.Text = ""
        Me.txt_localidad.Text = ""
        Me.txt_nacionalidad.Text = ""
        Me.cbx_club.Text = ""
        Me.cbx_puesto.Text = ""
        Me.dtp_alta_padron.Text = ""
        Me.dtp_fecha_nacimiento.Text = ""
        Me.txt_numero.Text = ""
        Me.cbx_es_jugador.Text = ""
        Me.txt_nro_documento.Text = ""
        Me.cbx_tipo_documento.Text = ""

    End Sub

    Private Sub cmd_Alta_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_Alta.Click
        HabilitadorBotones(False)
        HabilitadorLabels(True)
        txt_nro_documento.Focus()
    End Sub

    Private Sub cmd_guardar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_guardar.Click

        FechaValida = True
        CamposVacios = False

        If txt_apellido.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_calle.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_nombre.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_cp.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_localidad.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_nacionalidad.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_numero.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If txt_nro_documento.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If

        If cbx_club.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If cbx_puesto.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If dtp_alta_padron.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
            Dim Fecha As Date
            If Not (Date.TryParse(dtp_alta_padron.Text, Fecha)) Then
                SetTheRegion(dtp_alta_padron, 2, 2, 4)
                FechaValida = False
            Else
                If ((Date.Parse(dtp_alta_padron.Text) < Date.Parse("01/01/1900")) Or (Date.Parse(dtp_alta_padron.Text) > Date.Parse(Date.Now))) Then
                    SetTheRegion(dtp_alta_padron, 2, 2, 4)
                    FechaValida = False
                End If
            End If
        End If
        If dtp_fecha_nacimiento.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If
        If cbx_tipo_documento.Text = "" Then
            SetTheRegion(txt_apellido, 2, 2, 4)
            CamposVacios = True
        End If

        'Programar el Insert y validaciones boli
        'HabilitadorBotones(True)
        'HabilitadorLabels(False)
    End Sub

    Private Sub cmd_cancelar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_cancelar.Click
        Dim Respuesta As Double = MessageBox.Show("¿Esta seguro que desea cancelar?", "Confirmar", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
        If (Respuesta = 1) Then
            HabilitadorBotones(True)
            HabilitadorLabels(False)
            RellenaBordes()
        End If
    End Sub
    Private Sub Validador(ByVal txtCampo As Object, ByVal lblCampo As Object)
        If (txtCampo.Text = "") Then
            MessageBox.Show("El " + lblCampo.Text + " esta vacio", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            Exit Sub
        End If
    End Sub
    Private Sub cmd_buscar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_buscar.Click
        Me.txt_search.Visible = True
        Me.cmd_buscando.Visible = True
        Me.cmd_buscar.Visible = False
    End Sub

    Private Sub cmd_buscando_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_buscando.Click
        Me.txt_search.Visible = False
        Me.cmd_buscando.Visible = False
        Me.cmd_buscar.Visible = True
    End Sub

    Private Sub cmd_salir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_salir.Click
        Dim Respuesta As Integer = MessageBox.Show("¿Esta seguro que quiere salir?", "Confirmar", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
        If Respuesta = 1 Then
            End
        End If
    End Sub

    Private Sub txt_nro_documento_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txt_nro_documento.TextChanged

    End Sub

    Private Sub txt_nro_documento_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txt_nro_documento.KeyPress, txt_cp.KeyPress, txt_numero.KeyPress
        If InStr(1, "0123456789" & Chr(8), e.KeyChar) = 0 Then
            e.KeyChar = ""
        End If
        'If cbx_tipo_documento.Text = "DNI" Then
        Me.txt_nro_documento.MaxLength = 8
        'End If
    End Sub


    Private Sub txt_nombre_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txt_nombre.KeyPress, txt_apellido.KeyPress, txt_nacionalidad.KeyPress, txt_calle.KeyPress, txt_localidad.KeyPress
        If InStr(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .," & Chr(8), e.KeyChar) = 0 Then
            e.KeyChar = ""
        End If
    End Sub

    Private Sub CargaContenedorTipoDocumentoToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Me.Tipo_documentoTableAdapter.CargaContenedorTipoDocumento(Me.ACF_PAVDataSet.tipo_documento)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub CargaContenedorTipoDocumentoToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Me.Tipo_documentoTableAdapter.CargaContenedorTipoDocumento(Me.ACF_PAVDataSet.tipo_documento)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub CargaContenedorTipoDocumentoToolStripButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Me.Tipo_documentoTableAdapter.CargaContenedorTipoDocumento(Me.ACF_PAVDataSet.tipo_documento)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub CargaContenedorTipoDocumentoToolStripButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Me.Tipo_documentoTableAdapter.CargaContenedorTipoDocumento(Me.ACF_PAVDataSet.tipo_documento)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub


    Private Sub frmABMAlumno_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles gbx_club.Paint

        Dim p As New Pen(Color.Red, 2)
        e.Graphics.DrawRectangle(p, New Rectangle(cbx_tipo_documento.Location + New Size(-11, -11), cbx_tipo_documento.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_nro_documento.Location + New Size(-11, -11), txt_nro_documento.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_nombre.Location + New Size(-11, -11), txt_nombre.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_apellido.Location + New Size(-11, -11), txt_apellido.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(dtp_fecha_nacimiento.Location + New Size(-11, -11), dtp_fecha_nacimiento.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_nacionalidad.Location + New Size(-11, -11), txt_nacionalidad.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(dtp_alta_padron.Location + New Size(-11, -11), dtp_alta_padron.Size - New Size(2, 2)))
        p.Dispose()
    End Sub

    Private Sub frmABMAlumno_Paint3(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles gbx_direccion.Paint
        Dim p As New Pen(Color.Red, 2)
        e.Graphics.DrawRectangle(p, New Rectangle(txt_calle.Location + New Size(1, 1), txt_calle.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_numero.Location + New Size(1, 1), txt_numero.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_localidad.Location + New Size(1, 1), txt_localidad.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(txt_cp.Location + New Size(1, 1), txt_cp.Size - New Size(2, 2)))
        p.Dispose()
    End Sub

    Private Sub frmABMAlumno_Paint2(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles gbx_club.Paint
        Dim p As New Pen(Color.Red, 2)
        e.Graphics.DrawRectangle(p, New Rectangle(cbx_club.Location + New Size(1, 1), cbx_club.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(cbx_es_jugador.Location + New Size(1, 1), cbx_es_jugador.Size - New Size(2, 2)))
        e.Graphics.DrawRectangle(p, New Rectangle(cbx_puesto.Location + New Size(1, 1), cbx_puesto.Size - New Size(2, 2)))
        p.Dispose()
    End Sub
    Private Sub SetTheRegion(ByVal Objeto As Object, ByVal X As Double, ByVal Y As Double, ByVal Borde As Double)
        Objeto.Region = New Region(New Rectangle(X, Y, Objeto.Width - Borde, Objeto.Height - Borde))
    End Sub

    Private Sub RellenaBordes()
        SetTheRegion(cbx_tipo_documento, 0, 0, -4)
        SetTheRegion(txt_nro_documento, 0, 0, -4)
        SetTheRegion(txt_nombre, 0, 0, -4)
        SetTheRegion(txt_apellido, 0, 0, -4)
        SetTheRegion(dtp_fecha_nacimiento, 0, 0, -4)
        SetTheRegion(txt_apellido, 0, 0, -4)
        SetTheRegion(txt_apellido, 0, 0, -4)
        SetTheRegion(txt_apellido, 0, 0, -4)
        SetTheRegion(txt_apellido, 0, 0, -4)
    End Sub
End Class